home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 749 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: mail2news.demon.co.uk!wbriscoe.demon.co.uk
  2. From: walter briscoe <walter@wbriscoe.demon.co.uk>
  3. Newsgroups: comp.std.c
  4. Subject: valueless return statement in non-void function
  5. Date: Mon, 15 Apr 96 13:05:02 GMT
  6. Message-ID: <829573502snz@wbriscoe.demon.co.uk>
  7. Reply-To: walter@wbriscoe.demon.co.uk
  8. X-NNTP-Posting-Host: wbriscoe.demon.co.uk
  9. X-Newsreader: Demon Internet Simple News v1.30
  10. X-Mail2News-Path: wbriscoe.demon.co.uk
  11.  
  12. I recently had trouble moving some K&R code to ISO C.
  13.  
  14. Specifically, a function without a return statement was used to return a
  15. value with an implicit return at the } terminating the function.
  16.  
  17. Section 6.6.6.4 of ANSI/ISO 9899-1990 contains the Semantic restriction
  18. > If a return statement without an expression is executed, and the value
  19. > of the function call is used by the caller, the behavior is undefined.
  20.  
  21. It goes on to say:
  22. > Reaching the } that terminates the function is equivalent to executing
  23. > a return statement without an expression.
  24.  
  25. I am surprised/irritated that the undefined behavior is in the caller
  26. rather than the called function.
  27.  
  28. The Rationale, I have, associated with a draft of the standard makes no
  29. comment on the return statement.
  30.  
  31. I would like the next version of the standard to have an additional
  32. constraint:
  33. A return statement without an expression shall only appear in a function
  34. whose return type is void.
  35. causing the redundancy of:
  36. > If a return statement without an expression is executed, and the value
  37. > of the function call is used by the caller, the behavior is undefined.
  38.  
  39. The obvious objection to such a statement is that it conflicts with
  40. prior art.  I would answer that by making the implicit type of
  41. declarations void rather than int.  That would allow less unreasonable
  42. prior art to port without complaint.  I would have implicitly typed
  43. declarations deprecated in the next revision of the standard to
  44. facilitate their removal by a further revision.
  45. --
  46. walter briscoe
  47.